package config;

import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

/**
 *
 * config
 * 数据库的配置
 * 2018/6/10-21:44
 * 2018
 * Created by wuqiang on 2018/6/10.
 */
@Configuration
@PropertySource("classpath:db.properties")
public class DbConfig {

    @Autowired
    Environment env;

    @Bean(name = "dataSource")
    public BasicDataSource dataSource(){
        BasicDataSource ds=new BasicDataSource();
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl(env.getProperty("jdbc.url"));
        ds.setUsername(env.getProperty("jdbc.username"));
        ds.setPassword(env.getProperty("jdbc.password"));
        ds.setInitialSize(5);
        ds.setMaxTotal(10);
        return ds;
    }
}
